<script setup lang="ts">
import { ref, watch } from 'vue'
import { localCache } from '@/utils/cache'
// import { Avatar, Cellphone } from '@element-plus/icons-vue'
import PanelAccount from './panel-account.vue'
import PanelPhone from './panel-phone.vue'

const isRememberPwd = ref<boolean>(
  localCache.getCache('isRememberPwd') ?? false
)
const activeName = ref('account')
const accountRef = ref<InstanceType<typeof PanelAccount>>()
const phoneRef = ref<any>()
const handleTabs = () => {
  // console.log(activeName.value + '被点击')
  if (activeName.value === 'account') {
    accountRef.value?.accountLogin(isRememberPwd.value)
  } else {
    console.log(activeName.value + '被点击')
  }
}
watch(isRememberPwd, (newValue) => {
  localCache.setCache('isRememberPwd', newValue)
  console.log(newValue)
})
</script>
<template>
  <div class="login-panel">
    <h1 class="login-title">后台管理系统</h1>
    <div class="login-tabs">
      <el-tabs v-model="activeName" type="border-card" stretch>
        <el-tab-pane label="帐号登录" name="account">
          <template #label>
            <span class="custom-tabs-label">
              <el-icon><Avatar /></el-icon>
              <span class="tab-title">帐号登录</span>
            </span>
          </template>
          <PanelAccount ref="accountRef"></PanelAccount>
        </el-tab-pane>
        <el-tab-pane label="手机登录" name="phone">
          <template #label>
            <span class="custom-tabs-label">
              <el-icon><Cellphone /></el-icon>
              <span class="tab-title">手机登录</span>
            </span>
          </template>
          <PanelPhone ref="phoneRef"></PanelPhone>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="login-controls">
      <el-checkbox class="login-re" v-model="isRememberPwd">
        记住密码
      </el-checkbox>
      <el-link class="login-forgetpwd" type="primary" size="large">
        忘记密码
      </el-link>
    </div>
    <div class="login-btn">
      <el-button type="primary" size="large" @click="handleTabs"
        >立即登录</el-button
      >
    </div>
  </div>
</template>

<style scoped lang="less">
.login-panel {
  width: 330px;
  .login-title {
    text-align: center;
    color: var(--el-text-color-primary);
  }
  .login-tabs {
    .custom-tabs-label {
      display: flex;
      justify-content: center;
      align-items: center;
      .tab-title {
        padding: 0 5px;
      }
    }
  }
  .login-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    .login-re {
    }
    .login-forgetpwd {
    }
  }
  .login-btn {
    .el-button {
      width: 100%;
    }
  }
}
</style>
